import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class HomeWork {
    public static boolean oddEven(int[] array) {
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] % 2 != 0) {
                count++;
                if (3 == count) {
                    return true;
                }
            }else {
                count = 0;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[] array = {2, 2, 1, 2, 2 };
        System.out.println(oddEven(array));
    }
    public static int majorityElement(int[] array) {
        int ret = array[0];
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == ret) {
                count++;
            }else {
                count--;
            }
            if (count == 0) {
                ret = array[i + 1];
            }
        }
        return ret;
    }

    public static void main6(String[] args) {
        int[] array = {2, 2, 1, 1, 2, 2 };
        int ret = majorityElement(array);

    }
    public static int func(int[] array) {
        int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret = ret ^ array[i];
        }
        return  ret;
    }
    public static void main5(String[] args) {
        int[] array = {1, 2, 3, 2, 1};
        System.out.println(func(array));
    }
    public static int[] nums(int[] array, int target) {
        int[] ret = new int[2];
        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] + array[j] == target) {
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }
    public static void main4(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("输入数值：");
        int target = input.nextInt();
        int[] array = {2, 7, 11, 9, 5};
        nums(array, target);

    }
    public static void oddeven(int[] array) {
        //奇数在前，偶数在后;.
        //1.数组前面遇到偶数停止遍历，后面遇到奇数停止遍历
        //2.停止以后前和后交换
        //3.不停止就x向后加一，y向后减一
        int x = 0;//数组前面第一个元素
        int y = array.length - 1;//数组最后面元素
        int tmp = 0;//交换的变量
        while(x < y) {
            while (x < y && array[x] % 2 != 0) {
                //前面是奇数
                x++;
            }
            while (x < y && array[y] % 2 == 0) {
                //后面是偶数
                y--;
            }
            //前不是奇数，后不是偶数 - 交换
            tmp = array[x];
            array[x] = array[y];
            array[y] = tmp;
        }
    }

    public static void main3(String[] args) {
        int[] array = {1, 5, 2, 6, 3, 8, 9, 4, 10 ,7};
        oddeven(array);
        System.out.println(Arrays.toString(array));
    }
    public static int avg(int[] array) {
        int sum = 0;//求和变量
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        int mean = sum / array.length;
        return mean;
    }

    public static void main2(String[] args) {
        int[] array = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
        int ret = avg(array);
        System.out.println(ret);
    }
    public static void transform(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i] * 2;
        }
    }
    public static void main1(String[] args) {
        int[] array = {1, 2, 3, 4, 5};
        transform(array);
        System.out.println(Arrays.toString(array));
    }
}
